package com.bjxst;

import java.io.*;

/**字符输出流*/
/*IO流中专门提供了用于字符输出的流对象PrintWrite,该对象具有自动行刷新，不用调用flush();
* 缓冲字符输出流，特点是可以接行写出字符串，并且可通过println()方法实现自动换行*/
public class LineNumberDemo3 {
    public static void main(String[] args) {
       /*读取文本文件，可以用字符输入缓冲流和字符输入流
       * 也可以字符输入缓冲流和字节转字符流*/
        BufferedReader br = null;
       // BufferedWriter bw = null;
        PrintWriter pw =null;
        try{
           // 字符输入缓冲流和字符输入流
           // br = new BufferedReader(new FileReader("d:/b.txt"));
            //字符输入缓冲流和字节转字符流
            br = new BufferedReader(new InputStreamReader(new FileInputStream("d:/b.txt")));
            pw = new PrintWriter("d:/ccc.txt");//PrintWriter 本身是字符流直接读取
            String temp = "";
            int i = 1;
            while ((temp = br.readLine()) != null){
                pw.println(i +","+temp);
                i++;
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try{
                if(br != null){
                    br.close();
                }
                if(pw != null){
                    pw.close();
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}
